﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Tauren.Business.Infrastructure.Common;
using Tauren.Business.Service.DictionaryBLL;

namespace Tauren.Business.Core.Controllers
{
    /// <summary>
    /// 字典分类接口
    /// </summary>
    [Route("api/dictionary"), ApiVersion("1.0")]
    [ApiController]
    public class DictionaryController : ControllerBase
    {
        private IDictionaryService service;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="service"></param>
        public DictionaryController(IDictionaryService service)
        {
            this.service = service;
        }
        /// <summary>
        /// 分页获取 单位信息列表
        /// </summary>
        /// <param name="queryModel"></param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/pages")]
        public IActionResult Pages([FromBody] Entity.Global.QueryModel queryModel) => service.Pages(queryModel).ToJsonResult();

        /// <summary>
        /// 新增数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/add")]
        public IActionResult Add([FromBody] Entity.Input.Dictionary_Input input) => service.Add(input).ToJsonResult();


        /// <summary>
        /// 编辑单位信息
        /// </summary>
        /// <param name="input">单位信息</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/edit")]
        public IActionResult Editor([FromBody] Entity.Input.Dictionary_Input input) => service.Edit(input).ToJsonResult();

        /// <summary>
        /// 获取单个单位信息数据
        /// </summary>
        /// <param name="id">单位实体id</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/get/{id}")]
        public IActionResult Get([FromRoute] int id) => service.Get(id).ToJsonResult();

        /// <summary>
        /// 删除单位信息
        /// </summary>
        /// <param name="id">单位实体id</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/del/{id}")]
        public IActionResult Delete([FromRoute] int id) => service.Delete(id).ToJsonResult();
        /// <summary>
        /// 启用??
        /// </summary>
        /// <param name="id">单位ID</param> 
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/enable/{id}")]
        public IActionResult Enable(int id) => service.Enable(id).ToJsonResult();
        /// <summary>
        /// 获取字段数据
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/config/{type}")]
        public IActionResult Config([FromRoute] string type) => service.Config(type).ToJsonResult(true);
        /// <summary>
        /// 获取弹出框树形结构
        /// </summary> 
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/tree")]
        public IActionResult Tree() => service.Tree().ToJsonResult(true);
        /// <summary>
        /// 获取列表模板数据
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns> 
        [HttpPost, Route("v{version:apiVersion}/template/{key}")]
        public IActionResult Template([FromRoute] string key) => service.Template(key).ToJsonResult();
    }
}
